<?php

$oDb = &Database::get();
$oTpl = &App::getTemplate();
$oReq = &App::getRequest();

if ($oReq->get('revert'))
{
	$oDb->update(App::getT('user'), array('plugin_style' => ''), "id = '". App::getUser('id') ."'");
	App::gotoUrl('public.account.settings.theme', array(), App::format('Mod_Account.using_default_theme'));
}

if ( $id = $oReq->get('id') )
{
	$oDb->update(App::getT('user'), array('plugin_style' => $id), "id = '". App::getUser('id') ."'");
	$oTpl->assign(array
	(
		'done' => true,
		'link' => App::makeUrl('public.user', array('name' => App::getUser('user')))
	));
}

$themes = $oDb->getRows("
	SELECT 
		c.id, c.name, c.file, c.default
	FROM ". App::getT('css') ." AS c
");

$iDefaultTheme = '';
foreach ($themes as $aTheme) 
{
	if ($aTheme['default'])
	{
		$iDefaultTheme = $aTheme['id'];
		break;	
	}	
}

$oTpl->assign(array
(
	'themes' => $themes,
	'info' => App::format('Mod_Account.protheme_info', App::makeUrl('public.account.settings.design.act_reset_all')),
	'using' => App::getUser('plugin_style'),
	'iDefaultTheme' => $iDefaultTheme
));

?>
